home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Draw / Sources / PatFrame.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  4.1 KB  |  146 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                PatFrame.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef PATFRAME_H
  15. #include "PatFrame.h"
  16. #endif
  17.  
  18. #ifndef DRAWPART_H
  19. #include "DrawPart.h"
  20. #endif
  21.  
  22. // ----- Part Layer -----
  23.  
  24. #ifndef FWUTIL_H
  25. #include "FWUtil.h"
  26. #endif
  27.  
  28. // ----- OS Layer -----
  29.  
  30. #ifndef FWWINDOW_H
  31. #include "FWWindow.h"
  32. #endif
  33.  
  34. #ifndef FWMEMMGR_H
  35. #include "FWMemMgr.h"
  36. #endif
  37.  
  38. #ifndef FWEVENT_H
  39. #include "FWEvent.h"
  40. #endif
  41.  
  42. #ifndef FWCOLOR_H
  43. #include "FWColor.h"
  44. #endif
  45.  
  46. #ifndef FWRECSHP_H
  47. #include "FWRecShp.h"
  48. #endif
  49.  
  50. //========================================================================================
  51. // Runtime Informations
  52. //========================================================================================
  53.  
  54. #ifdef FW_BUILD_MAC
  55. #pragma segment odfdrawframes
  56. #endif
  57.  
  58. //========================================================================================
  59. // CLASS CPatternFrame
  60. //========================================================================================
  61.  
  62. //----------------------------------------------------------------------------------------
  63. // CPatternFrame::CPatternFrame
  64. //----------------------------------------------------------------------------------------
  65.  
  66. CPatternFrame::CPatternFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CDrawPart *drawPart) :
  67.     CFloatingWindowFrame(ev, odFrame, presentation, drawPart),
  68.     fGrid(2, 6, FW_CPoint(FW_IntToFixed(2), FW_IntToFixed(2)), FW_CPoint(kPatternCellSize, kPatternCellSize), FW_IntToFixed(1))
  69. {
  70. }
  71.  
  72. //----------------------------------------------------------------------------------------
  73. // CPatternFrame::~CPatternFrame
  74. //----------------------------------------------------------------------------------------
  75.  
  76. CPatternFrame::~CPatternFrame()
  77. {
  78. }
  79.  
  80. //----------------------------------------------------------------------------------------
  81. //    CPatternFrame::Draw
  82. //----------------------------------------------------------------------------------------
  83.  
  84. void CPatternFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  85. {
  86.     FW_CFacetContext fc(ev, odFacet, invalidShape);
  87.     fc.SetMapping(fMapping);
  88.  
  89.     EraseBackground(ev, fc);
  90.  
  91.     //    ----- Draw the grid -----
  92.     fGrid.DrawGridBorders(fc);
  93.     
  94.     // ----- Draw each color -----
  95.     FW_CRect rect;
  96.     FW_CRectShape rectShape(FW_kZeroRect, FW_kFill);
  97.     FW_PPattern* pattern;
  98.     for (unsigned long index = 0; index < 12; index++)
  99.     {
  100.         fGrid.GetCellInterior(index, rect);
  101.         rectShape.SetRectangle(rect);
  102.         rectShape.GetStyle()->SetPattern(fDrawPart->GetPattern(index));
  103.         rectShape.Render(fc);
  104.     }
  105. }
  106.  
  107. //----------------------------------------------------------------------------------------
  108. //    CPatternFrame::DoMouseDown
  109. //----------------------------------------------------------------------------------------
  110.  
  111. FW_Boolean CPatternFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  112. {
  113.     FW_CPoint where = theMouseEvent.GetLogicalMousePosition(ev, fMapping);
  114.     
  115.     unsigned long patIndex;    
  116.     if (fGrid.FindCell(where, patIndex))
  117.     {
  118.         if (theMouseEvent.IsCopyModifier(ev))
  119.             fDrawPart->SetFramePattern(ev, patIndex);
  120.         else
  121.             fDrawPart->SetFillPattern(ev, patIndex);    
  122.     }
  123.  
  124.     return TRUE;
  125. }
  126.  
  127. //----------------------------------------------------------------------------------------
  128. // CPatternFrame::FacetAdded
  129. //----------------------------------------------------------------------------------------
  130. //    When ODWindow moves back to ODFrame we will be able to move this code
  131. //    back to the constructor
  132.  
  133. void CPatternFrame::FacetAdded(Environment* ev, ODFacet* facet)
  134. {
  135.     // ----- Call inherited first -----
  136.     CFloatingWindowFrame::FacetAdded(ev, facet);
  137.     
  138.     // ----- Resize my Window -----
  139.     FW_CRect gridRect;
  140.     fGrid.GetExteriorGridRect(gridRect);
  141.     gridRect.Inset(-FW_IntToFixed(2), -FW_IntToFixed(2));
  142.     FW_CPoint windowSize(gridRect.Width(), gridRect.Height());
  143.     GetWindow(ev)->SetWindowSize(ev, windowSize);
  144. }
  145.  
  146.